<%@ page language="java" contentType="text/html; charset=UTF-8" 
import="com.google.appengine.api.datastore.KeyFactory,java.util.*,org.windblog.core.entity.*,org.windblog.core.*"  pageEncoding="UTF-8"%>
<%
	String comment_status = request.getParameter("comment_status");
	List<Comment> comments = null ;  //要列出的comments

	if(comment_status==null)
	{
		comments = CommentService.getAllComments();
		comment_status="";
	}else if(comment_status.equals("moderated"))
	{
		comments = CommentService.getPendingComments();
	}else if(comment_status.equals("approved"))
	{
		comments = CommentService.getApprovedComments();
	}else if(comment_status.equals("spam"))
	{
		comments = CommentService.getSpamComments();
	}
	
	
%>
		<jsp:include page="header.jsp"></jsp:include>
		<jsp:include page="sidebar.jsp"></jsp:include>
		<script type="text/javascript">
			$(function(){
				// Accordion
				$("#commentsButton").button( "option", "icons", {primary:'ui-icon-carat-1-e'} );
			});
		</script>
		<div id="content">
			<h2>Edit Comments</h2>
			<hr/>
			<div id="commentspanel" class="ui-widget ui-widget-content ui-corner-all" style="margin-top:10px;padding:0;width:800px"> 
			<h3 class="ui-widget-header" style="padding:5px 10px;font-size:12px;">Comments</h3>
			<ul class="menu">
				<li<%=comment_status.equals("")?" style=\"font-weight: bold;\"":"" %>><a href="/admin/editComments.jsp">All</a></li>
				<li<%=comment_status.equals("moderated")?" style=\"font-weight: bold;\"":"" %>><a href="/admin/editComments.jsp?comment_status=moderated">Pending (<%=CommentService.getPendingComments().size() %>)</a></li>
				<li<%=comment_status.equals("approved")?" style=\"font-weight: bold;\"":"" %>><a href="/admin/editComments.jsp?comment_status=approved">Approved</a></li>
				<li<%=comment_status.equals("spam")?" style=\"font-weight: bold;\"":"" %>><a href="/admin/editComments.jsp?comment_status=spam">Spam (<%=CommentService.getSpamComments().size() %>)</a></li>
			</ul>
				<table id="posts" border="1" cellspacing="0" style="width:100%">
					<thead>
					<tr>
						<th>Author</th>
						<th>Comment</th>
						<th>In Response To</th>
					</tr>
					</thead>
					<%
						
						if(comments!=null)
						{
							for(Comment comment : comments)
							{
								Post post = comment.getPost();
								%>
					<tr class="mzone" style="background:<%=comment.isApproved()?"white":"#F6E3CE" %>">
						<td>
						<strong><%= comment.getAuthor() %></strong><br/>
						<%=
							comment.getAuthorURL()==null?"":"<a href=\""+comment.getAuthorURL()+"\">"+comment.getAuthorURL()+"</a><br/>"
						%>
						<%=
							comment.getAuthorEmail()==null?"":"<a href=\"mailto:"+comment.getAuthorEmail()+"\">"+comment.getAuthorEmail()+"</a><br/>"
						%>
						<%=
							comment.getAuthorIP()==null?"":"<a href=\"#"+comment.getAuthorIP()+"\">"+comment.getAuthorIP()+"</a><br/>"
						%>
						</td>
						<td>
						<span style="color:black">Submitted on</span> <%=comment.getDate().toString()%><br/>
						<span style="color:black;padding:10px 20px;display:block;"><%=comment.getContent() %></span>
						<div>&nbsp;<span class="Action" style="display:none">
						<a href="setcomment?comment=<%=comment.getStrKey() %>&action=<%= comment.isApproved()?"unapprove":"approve"%>&curview=<%=comment_status %>"><%= comment.isApproved()?"<span style=\"color:#FF8000\">Unapprove</span>":"<span style=\"color:green\">Approve</span>"%></a>
						|<a href="setcomment?comment=<%=comment.getStrKey() %>&action=spam&curview=<%=comment_status %>">Spam</a>
						|<a href="deletecomment?comment=<%=comment.getStrKey() %>&action=spam&curview=<%=comment_status %>" style="color:red">Delete</a>
						|<a href="Edit">Edit</a>
						|<a href="Reply">Reply</a></span></div>
						</td>
						<td><a href="<%=post.getEditLink() %>"><%=post.getTitle() %></a><br/>
						<a href="p=3"><%=post.getCommentCount() %></a>&nbsp;&nbsp;<a href="<%=post.getPermalink() %>">#</a>
						</td>
					</tr>
								<%
							}
						}
					%>
				</table>
			</div>
		</div>
		
		<jsp:include page="footer.jsp"></jsp:include>
